from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-26 14:10:20.293887
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 26, Oct, 2022
Time: 14:10:27
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.8258
Nobs: 821.000 HQIC: -51.1440
Log likelihood: 10681.4 FPE: 5.03955e-23
AIC: -51.3422 Det(Omega_mle): 4.51930e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.290711 0.051837 5.608 0.000
L1.Burgenland 0.108614 0.035155 3.090 0.002
L1.Kärnten -0.106735 0.018723 -5.701 0.000
L1.Niederösterreich 0.211748 0.073555 2.879 0.004
L1.Oberösterreich 0.102183 0.070475 1.450 0.147
L1.Salzburg 0.250341 0.037403 6.693 0.000
L1.Steiermark 0.036369 0.049003 0.742 0.458
L1.Tirol 0.107328 0.039744 2.700 0.007
L1.Vorarlberg -0.058126 0.034193 -1.700 0.089
L1.Wien 0.061850 0.062883 0.984 0.325
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063164 0.107180 0.589 0.556
L1.Burgenland -0.033200 0.072687 -0.457 0.648
L1.Kärnten 0.047648 0.038713 1.231 0.218
L1.Niederösterreich -0.172521 0.152085 -1.134 0.257
L1.Oberösterreich 0.385771 0.145716 2.647 0.008
L1.Salzburg 0.286481 0.077336 3.704 0.000
L1.Steiermark 0.104287 0.101320 1.029 0.303
L1.Tirol 0.314264 0.082176 3.824 0.000
L1.Vorarlberg 0.025422 0.070699 0.360 0.719
L1.Wien -0.014734 0.130019 -0.113 0.910
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187617 0.026597 7.054 0.000
L1.Burgenland 0.090578 0.018037 5.022 0.000
L1.Kärnten -0.008477 0.009607 -0.882 0.378
L1.Niederösterreich 0.264973 0.037740 7.021 0.000
L1.Oberösterreich 0.125921 0.036159 3.482 0.000
L1.Salzburg 0.048465 0.019191 2.525 0.012
L1.Steiermark 0.017117 0.025142 0.681 0.496
L1.Tirol 0.094968 0.020392 4.657 0.000
L1.Vorarlberg 0.059494 0.017544 3.391 0.001
L1.Wien 0.120268 0.032264 3.728 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105541 0.027283 3.868 0.000
L1.Burgenland 0.044801 0.018503 2.421 0.015
L1.Kärnten -0.016383 0.009855 -1.662 0.096
L1.Niederösterreich 0.193972 0.038714 5.010 0.000
L1.Oberösterreich 0.293728 0.037093 7.919 0.000
L1.Salzburg 0.116602 0.019686 5.923 0.000
L1.Steiermark 0.099177 0.025792 3.845 0.000
L1.Tirol 0.117669 0.020919 5.625 0.000
L1.Vorarlberg 0.070828 0.017997 3.936 0.000
L1.Wien -0.026538 0.033097 -0.802 0.423
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120547 0.049561 2.432 0.015
L1.Burgenland -0.050559 0.033611 -1.504 0.133
L1.Kärnten -0.040560 0.017901 -2.266 0.023
L1.Niederösterreich 0.170556 0.070325 2.425 0.015
L1.Oberösterreich 0.136926 0.067380 2.032 0.042
L1.Salzburg 0.285731 0.035761 7.990 0.000
L1.Steiermark 0.033528 0.046851 0.716 0.474
L1.Tirol 0.166405 0.037999 4.379 0.000
L1.Vorarlberg 0.105001 0.032692 3.212 0.001
L1.Wien 0.074211 0.060122 1.234 0.217
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.057687 0.039227 1.471 0.141
L1.Burgenland 0.039181 0.026603 1.473 0.141
L1.Kärnten 0.050416 0.014169 3.558 0.000
L1.Niederösterreich 0.226267 0.055662 4.065 0.000
L1.Oberösterreich 0.282968 0.053331 5.306 0.000
L1.Salzburg 0.052245 0.028304 1.846 0.065
L1.Steiermark -0.009543 0.037082 -0.257 0.797
L1.Tirol 0.150831 0.030076 5.015 0.000
L1.Vorarlberg 0.071115 0.025875 2.748 0.006
L1.Wien 0.079691 0.047586 1.675 0.094
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170312 0.046896 3.632 0.000
L1.Burgenland -0.005342 0.031804 -0.168 0.867
L1.Kärnten -0.061430 0.016939 -3.627 0.000
L1.Niederösterreich -0.082328 0.066544 -1.237 0.216
L1.Oberösterreich 0.192678 0.063758 3.022 0.003
L1.Salzburg 0.058173 0.033838 1.719 0.086
L1.Steiermark 0.229024 0.044332 5.166 0.000
L1.Tirol 0.495852 0.035956 13.790 0.000
L1.Vorarlberg 0.050306 0.030934 1.626 0.104
L1.Wien -0.045393 0.056890 -0.798 0.425
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156451 0.053778 2.909 0.004
L1.Burgenland -0.011379 0.036471 -0.312 0.755
L1.Kärnten 0.065574 0.019424 3.376 0.001
L1.Niederösterreich 0.201448 0.076309 2.640 0.008
L1.Oberösterreich -0.059531 0.073114 -0.814 0.416
L1.Salzburg 0.217735 0.038804 5.611 0.000
L1.Steiermark 0.112345 0.050838 2.210 0.027
L1.Tirol 0.078811 0.041232 1.911 0.056
L1.Vorarlberg 0.124905 0.035473 3.521 0.000
L1.Wien 0.115411 0.065238 1.769 0.077
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350047 0.031359 11.163 0.000
L1.Burgenland 0.006132 0.021267 0.288 0.773
L1.Kärnten -0.023676 0.011327 -2.090 0.037
L1.Niederösterreich 0.224858 0.044497 5.053 0.000
L1.Oberösterreich 0.174235 0.042634 4.087 0.000
L1.Salzburg 0.048233 0.022627 2.132 0.033
L1.Steiermark -0.016561 0.029644 -0.559 0.576
L1.Tirol 0.109849 0.024043 4.569 0.000
L1.Vorarlberg 0.074094 0.020685 3.582 0.000
L1.Wien 0.053834 0.038041 1.415 0.157
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041722 0.152839 0.190441 0.159055 0.125428 0.115777 0.066799 0.227243
Kärnten 0.041722 1.000000 -0.002557 0.129740 0.042105 0.096521 0.429179 -0.052807 0.101079
Niederösterreich 0.152839 -0.002557 1.000000 0.338014 0.156235 0.300541 0.112706 0.184876 0.329129
Oberösterreich 0.190441 0.129740 0.338014 1.000000 0.233775 0.333249 0.174825 0.173874 0.264123
Salzburg 0.159055 0.042105 0.156235 0.233775 1.000000 0.146872 0.130609 0.149945 0.136142
Steiermark 0.125428 0.096521 0.300541 0.333249 0.146872 1.000000 0.154530 0.141921 0.079496
Tirol 0.115777 0.429179 0.112706 0.174825 0.130609 0.154530 1.000000 0.116514 0.156641
Vorarlberg 0.066799 -0.052807 0.184876 0.173874 0.149945 0.141921 0.116514 1.000000 0.008528
Wien 0.227243 0.101079 0.329129 0.264123 0.136142 0.079496 0.156641 0.008528 1.000000